#include <stdio.h>
#include <malloc.h>

typedef int E;

struct LNode {
    E element;
    struct LNode *next;
};

typedef struct LNode *Node;

void initStack(Node head) {
    head->next = NULL;
}

_Bool pushStack(Node head, E element) {
    Node node = malloc(sizeof(struct LNode));   //创建新的结点
    if (node == NULL) return 0;   //失败就返回0
    node->next = head->next;   //将当前结点的下一个设定为头结点的下一个
    node->element = element;   //设置元素
    head->next = node;   //将头结点的下一个设定为当前结点
    return 1;
}

_Bool isEmpty(Node head) {
    return head->next == NULL;
}

E popStack(Node head) {
    Node tmp = head->next;
    E e = tmp->element;
    head->next = head->next->next;
    free(tmp);
    return e;
}

void printStack(Node head) {
    head = head->next;
    while (head) {
        printf("%d ", head->element);
        head = head->next;
    }
    printf("|\n");
}

int main() {
    struct LNode head;
    initStack(&head);
    for (int i = 0; i < 3; ++i) {
        pushStack(&head, i * 100);
    }
    printStack(&head);
    while (!isEmpty(&head)){
        printf("%d ", popStack(&head));
    }
}